const express = require('express');
const { createProxyMiddleware, responseInterceptor} = require('http-proxy-middleware');
const cors = require('cors');

const app = express();
app.use(cors())

app.use(
    '/', // 你希望代理的路径
    createProxyMiddleware({
        target: 'http://127.0.0.1:8080', // 目标HTTPS服务器地址
        changeOrigin: true, // 是否更改请求源头
        secure: false, // 如果是HTTPS目标，设置为false以接受自我签名证书
        selfHandleResponse:true,
        on: {
            proxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
                return responseBuffer;
            }),
        },
    })
);


app.listen(8081, () => {
    console.log('Proxy server is running on port 8081');
});
